package com.boc.langxiang.presenter.shop;

import com.boc.langxiang.contract.shop.ProductGoodsContract;
import com.boc.langxiang.entity.request.ProductGoodsRequest;
import com.boc.langxiang.entity.response.BaseResponse;
import com.boc.langxiang.entity.response.ProductListContent;
import com.boc.langxiang.net.HandleErrorSubscriber;

import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by Li Guoxi on 2016/7/8.
 */
public class ProductGoodsPresenter extends SuperPresenter implements ProductGoodsContract, ProductGoodsContract.Presenter {
    private View mView;

    public ProductGoodsPresenter(View view) {
        super(view);
        this.mView = view;

    }

    @Override
    public void refresh(ProductGoodsRequest request) {
        mView.showLoading();
        mService.getProductGoods(request.params())
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .unsubscribeOn(Schedulers.io())
                .subscribe(new HandleErrorSubscriber<BaseResponse<ProductListContent>>(mView) {
                    @Override
                    public void onSuccess(BaseResponse<ProductListContent> response) {
                        mView.hideLoading();
                        mView.onRefreshSuccess(response.getContent());
                    }
                });
    }

    @Override
    public void loadMore(ProductGoodsRequest request) {
        mService.getProductGoods(request.params())
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .unsubscribeOn(Schedulers.io())
                .subscribe(new HandleErrorSubscriber<BaseResponse<ProductListContent>>(mView) {
                    @Override
                    public void onSuccess(BaseResponse<ProductListContent> response) {
                        mView.onLoadMoreSuccess(response.getContent());
                    }
                });
    }
}
